<?php
namespace app\admin\controller;
use think\Controller;

class Brand extends Controller
{
    public function lst()
    {
        return view();
    }

    public function add()
    {
        if(request()->isPost()){
            $data = input('post.');

            if($_FILES['brand_img']['tmp_name']){
                $data['brand_img'] = $this->upload();
            }



            $add = db('brand')->insert($data);
            if($add){
                $this->success("添加品牌成功");
            }else{
                $this->error("添加品牌失败！");
            }
        }
        return view();
    }

    public function edit()
    {
        return view();
    }

    public function del()
    {

    }

    public function upload()
    {
        $file = request()->file('brand_img');

        if($file){
            $info = $file->move(ROOT_PATH.'public'.DS.'static'.DS.'uploads');
            if($info){
                return $info->getSaveName();
            }else{
                echo $file->getError();
                die();
            }
        }
    }
}
